<template>
    <ui-main>

        <ui-pull @load="getListData" v-model="listData" :total="total" :num.sync="pageNumber" ref="pull">
            <van-cell v-for="(item,index) of listData" :key="index"  :value="item.report_time_str"  is-link @click="detail(item)">
                <template slot="title">
                    <div class="van-cell-text">{{item.report_title}}</div>
                    <van-tag type="success">{{item.labelName}}</van-tag>
                </template>
            </van-cell>
        </ui-pull>

        <van-button square slot="footer" size="large" type="primary" @click="addItem()">填写</van-button>


        <ui-page ref="互动交流添加">
                <!-- <div slot="header"></div>  -->
                <add v-on:doActiveFalse='clickToHidden' :isActive.sync="add.isActive" ></add>
        </ui-page>
    </ui-main>
</template>

<script>
    import ct from '../mixins/ct';
    import add from './add'
    export default {
        components: {
            add
        },

        mixins: [ct],
        data() {
            return {
                // 数据源
                // 轮播图片
                images: [
                    'http://img.sccnn.com/bimg/339/28115.jpg',
                    'http://5b0988e595225.cdn.sohucs.com/images/20171002/4b8d3440f8c74e72bbcf554ced7f5d7a.jpeg',
                    'http://spider.nosdn.127.net/fb987efbc0821f3c8a2f2aea1d47767d.gif'
                ],
                add: {
                    isActive: false
                },
                // 数据
                listData: [],
                // 其他
                // ajax 总次数
                listDataAjaxNum: 0,
                // 页数
                pageNumber: 1,
                // 页码
                pageSize: 20,
                // 总记录数
                total: 0,
                user: null
            };
        },
        watch: {
            // 监听切换标签
            active() {
                this.$refs.pull && this.$refs.pull.reload();
            }
        },
        mounted() {
            this.user = JSON.parse(localStorage.getItem("user"));
            console.log('fuck=',this.user, this.user.person_id, this.user.county_no);
        },
        methods: {

             clickToHidden(index) {
                //回调
                this.$refs['互动交流添加'].close();
                if (index == 'save') { //保存成功返回
                    this.$toast("添加成功");
                    this.pageNumber = 1;
                    this.getListData({isDownScrolling: true});
                } 
            },

            addItem() {
                this.isChildAdd = '1';
                this.$refs['互动交流添加'].open();
            },

            getListData({isDownScrolling}) {

                let ajaxNum = ++this.listDataAjaxNum;

                this.$$getReportList({
                    pageNumber: this.pageNumber,
                    pageSize: this.pageSize,
                    person_id: this.user.person_id,
                    county_no: this.user.county_no
                }).then(data => {
                    if (this.listDataAjaxNum === ajaxNum) {
                        this.pageNumber++;
                        this.total = data.total;

                        if (isDownScrolling) {
                            this.listData = data.content;
                        } else {
                            this.listData = [...this.listData, ...data.content];
                        }
                        for (let index = 0; index < this.listData.length; index++) {
                            let item = this.listData[index];
                            console.log(item.report_type,22222222222);
                            if(item.report_type === '3') {
                                item.labelName =  "厅长信箱";
                            } else if(item.report_type === '4') {
                                item.labelName =  "电子信访";
                            } else if(item.report_type === '5') {
                                item.labelName =  "举报信箱";
                            } else if(item.report_type === '6') {
                                item.labelName =  "在线咨询";
                            } 
                            
                        }
                        console.log(this.listData,1111111111111111111111);

                        this.$refs.pull && this.$refs.pull.endSuccess();
                    }
                }).catch(e => {
                    console.error(e);
                    if (this.listDataAjaxNum === ajaxNum) {
                        this.$refs.pull && this.$refs.pull.endSuccess();
                    }
                });
            },
            detail(item) {
                this.$router.push({
                    path: '/hdjlxx',
                    query: {
                        id: item.id
                    }
                })
            },

           
        },
      
    }
</script>

<style lang="scss" scoped>
    .van-button--primary {
        color: #fff;
        background-color: #0094da;
        border: 1px solid #0094da;
    }
</style>

